﻿using RpcHelper;
using SqlExecHelper;

using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class ReduceInRankConfigDAL : SqlExecHelper.SqlBasicClass
        {
                public ReduceInRankConfigDAL() : base("ReduceInRankConfig")
                {

                }
                public ReduceInRankConfig Get (long rpcMerId, long serverId)
                {
                        return this.GetRow<ReduceInRankConfig> (new ISqlWhere[] {
                                new SqlWhere("RpcMerId", System.Data.SqlDbType.BigInt){Value=rpcMerId},
                                new SqlWhere("ServerId", System.Data.SqlDbType.BigInt){Value=serverId},
                        });
                }
                public long GetId(long rpcMerId, long serverId)
                {
                        return this.ExecuteScalar<long>("Id", new ISqlWhere[] {
                                new SqlWhere("RpcMerId", System.Data.SqlDbType.BigInt){Value=rpcMerId},
                                new SqlWhere("ServerId", System.Data.SqlDbType.BigInt){Value=serverId},
                        });
                }
                public void Set(long id, ReduceInRankDatum datum)
                {
                        if(!this.Update(datum, "Id", id))
                        {
                                throw new ErrorException ("rpc.reduceInRank.set.error");
                        }
                }
                public void Add(AddReduceInRank add)
                {
                        this.Insert(add);
                }
                public void Clear (long serverId)
                {
                        base.Drop ("ServerId", serverId);
                }
                public void Drop(long id)
                {
                        if(!this.Drop("Id", id))
                        {
                                throw new ErrorException ("rpc.reduceInRank.drop.error");
                        }
                }
        }
}
